package edu.hitsz;

import edu.hitsz.Rank.RankListDAOMPL;
import edu.hitsz.application.Main;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class setName {
    private JPanel mainPanel;
    private JLabel label;
    private JPanel labelPanel;
    private JPanel textPanel;
    private JTextField nameField;
    private JPanel buttonPanel;
    private JButton yesButton;
    private JButton noButton;

    // 得分排行榜对象
    public static RankListDAOMPL rankListDAO = new RankListDAOMPL();

    // 排行榜对象
    public static Ranking ranking = null;

    public setName() {
        noButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Main.start.getGame().setNameFrame.dispose();
                int score = Main.start.getGame().getScore();
                int mode = Main.start.getGame().getMode();
                String name = "testUserName";
                RankListDAOMPL.setPath(mode);

                rankListDAO = rankListDAO.ranking(name, score);
                ranking = new Ranking(rankListDAO);
                ranking.setModeLabel(mode);
                Main.cardPanel.add(ranking.getMainPanel());
                Main.cardLayout.last(Main.cardPanel);
            }
        });
        yesButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Main.start.getGame().setNameFrame.dispose();
                int score = Main.start.getGame().getScore();
                int mode = Main.start.getGame().getMode();
                String name = nameField.getText();
                RankListDAOMPL.setPath(mode);

                rankListDAO = rankListDAO.ranking(name, score);
                ranking = new Ranking(rankListDAO);
                ranking.setModeLabel(mode);
                Main.cardPanel.add(ranking.getMainPanel());
                Main.cardLayout.last(Main.cardPanel);

            }
        });

    }

    public JPanel getMainPanel() {
        return mainPanel;
    }
}
